package com.edu.robot.core.service.impl;

import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;

import java.util.Arrays;

/**
 * @program: KQAIA
 * @description:
 * @author: 无恙
 * @create: 2025-04-15 14:08
 **/


public class main {


		public static GenerationResult callWithMessage() throws ApiException, NoApiKeyException, InputRequiredException {
			Generation gen = new Generation();
			Message systemMsg = Message.builder()
					.role(Role.SYSTEM.getValue())
					.content("You are a helpful assistant.")
					.build();
			Message userMsg = Message.builder()
					.role(Role.USER.getValue())
					.content("你是谁？")
					.build();
			GenerationParam param = GenerationParam.builder()
					// 若没有配置环境变量，请用百炼API Key将下行替换为：.apiKey("sk-xxx")
					.apiKey("sk-a4298b6daa5c4efb940d11518e960a65")
					.model("qwen-plus")
					.messages(Arrays.asList(systemMsg, userMsg))
					.resultFormat(GenerationParam.ResultFormat.MESSAGE)
					.build();
			return gen.call(param);
		}
		public static void main(String[] args) {
			try {
				GenerationResult result = callWithMessage();
				System.out.println(result.getOutput().getChoices().get(0).getMessage().getContent());
			} catch (ApiException | NoApiKeyException | InputRequiredException e) {
				System.err.println("错误信息："+e.getMessage());
				System.out.println("请参考文档：https://help.aliyun.com/zh/model-studio/developer-reference/error-code");
			}
			System.exit(0);
		}


}
